home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE20 / TIPTRIX / LISTING3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-17  |  1.4 KB  |  57 lines

  1. function ExtractName(const Filename: String): String;
  2.   { from my XProcs library }
  3. var aExt : String;
  4.     aPos : Integer;
  5. begin
  6.   aExt := ExtractFileExt(Filename);
  7.    Result := ExtractFileName(Filename);
  8.    if aExt <> '' then begin
  9.      aPos:=Pos(aExt,Result);
  10.      if aPos>0 then Delete(Result,aPos,Length(aExt));
  11.    end;
  12. end;
  13.  
  14. procedure CheckProcedures(aDb: TDataBase);
  15. var
  16.   aPath : String;
  17.   aSearch : TSearchRec;
  18.   aResult : Integer;
  19.   aProcs : TStringList;
  20.   procedure UpdateSql(const aFile: String);
  21.   var aProc: String;
  22.       i: Integer;
  23.   begin
  24.     if FileExists(aFile) then begin
  25.       aProc:=ExtractName(aFile);
  26.       with TQuery.Create(nil) do
  27.       try
  28.         DataBaseName := aDb.DataBaseName;
  29.         if aProcs.Find(aProc,i) then begin
  30.           SQL.Add(Format('DROP PROCEDURE %s',[aProc]));
  31.           ExeSQL;
  32.         end;
  33.         ParamCheck := False;
  34.         SQL.LoadFromFile(aFile);
  35.         ExecSQL;
  36.       finally
  37.         Free;
  38.       end;
  39.     end;
  40.   end;
  41. begin
  42.   aPath := ExtractFilePath(ParamStr(0))+'sql\';
  43.   aProcs := TStringList.Create;
  44.   try
  45.     aProcs.Sorted := True;
  46.     Session.GetStoredProcNames(aDb.DataBaseName, aProcs);
  47.     aResult := FindFirst(aPath+'*.sql',faAnyFile,aSearch);
  48.     while aResult = 0 do begin
  49.       UpdateSQL(aPath+aSearch.Name);
  50.       aResult := FindNext(aSearch);
  51.     end;
  52.     FindClose(aSearch);
  53.   finally
  54.     aProcs.Free;
  55.   end;
  56. end;
  57.